package com.zhang.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhang.domain.Manager;
import com.zhang.domain.Menu;
import com.zhang.mapper.MenuMapper;
import com.zhang.query.MenuQuery;
import com.zhang.service.IMenuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zh
 * @create 2022-02-15 17:12
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class IMenuServiceImpl implements IMenuService {
    @Resource
    private MenuMapper mapper;
    @Transactional
    @Override
    public void update(Menu m) {
        mapper.update(m);
    }
    @Transactional
    @Override
    public void add(Menu m) {
        mapper.add(m);
    }
    @Transactional
    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public PageInfo<Menu> selectData(MenuQuery query) {
        PageHelper.startPage(query.getCurrentPage(),query.getPageSize());
        List<Menu> menus = mapper.queryData(query);
        Page<Menu> page = (Page<Menu>) menus;
        return page.toPageInfo();
    }
    @Transactional
    @Override
    public void deleteAll(Long[] id) {
        mapper.deleteAll(id);
    }

    @Override
    public List<Menu> selAllMenu() {
        return mapper.selAllMenu();
    }
}
